package com.qing.library_manager.common.util;

import com.qing.library_manager.domain.dto.ManagerInfoDTO;
import io.jsonwebtoken.Claims;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>TODO</p>
 *
 * @author Yjx
 * @version 1.0.0
 * @since 2021/11/25
 **/
public class ManagerClaimsUtil {

    private static final String MANAGERID = "mangerId";

    private static final String MANAGERNAME = "managerName";

    private static final String MANAGERPHONE = "managerPhone";

    /**
     * 将manger信息封装成map
     *
     * @param managerInfoDTO
     * @return map
     */
    public static Map<String, Object> managerToClaims(ManagerInfoDTO managerInfoDTO) {
        Map<String, Object> claims = new HashMap<>();
        claims.put(MANAGERID, managerInfoDTO.getManagerId());
        claims.put(MANAGERNAME, managerInfoDTO.getManagerName());
        claims.put(MANAGERPHONE,managerInfoDTO.getManagerPhone());
        return claims;
    }

    /**
     * 解析manager信息
     *
     * @param claims 载荷
     * @return managerDTO
     */
    public static ManagerInfoDTO claimsToMangerLoginInfo(Claims claims) {
        ManagerInfoDTO managerInfoDTO = new ManagerInfoDTO();
        managerInfoDTO.setManagerId(String.valueOf(claims.get(MANAGERID)));
        managerInfoDTO.setManagerName(String.valueOf(claims.get(MANAGERNAME)));
        managerInfoDTO.setManagerPhone(String.valueOf(claims.get(MANAGERPHONE)));
        return managerInfoDTO;
    }

}
